from django.core.management import setup_environ
import tigeralbum.settings
setup_environ(tigeralbum.settings)

import os
import random
from datetime import datetime
from hashlib import sha1
from tigeralbum.main.models import Photo
from tigeralbum.util import thisdirpath

# The boundaries of Princeton's campus. We'll be randomly placing
# these seed photos within these boundaries.
X = 40.34060447080497, 40.3508911370046
Y = -74.66664071833804, -74.64430328166202
PHOTOS_PATH = thisdirpath('photos', __file__)

def randomsign():
    return 1 if random.random() > 0.5 else -1

for i, path in enumerate(os.listdir(PHOTOS_PATH)):
    path = os.path.join(PHOTOS_PATH, path)
    print('[%d] Adding photo %s' % (i, path))
    with open(path, 'rb') as image:
        photo = Photo(caption=unicode(i),
                      location_x=X[0] + random.random() * (X[1] - X[0]),
                      location_y=Y[0] + random.random() * (Y[1] - Y[0]),
                      approved=True,
                      dt_submitted=datetime.now(),
                      n_flagged=0,
                      n_likes=0)
        photo.save_with(image)
